#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#define REP(i,n) for(int i=0;i<int(n);++i)

using namespace std;

const int inf = 1<<29;

typedef pair<int,int> pii;
int n;
int a[1010];
int dp[1010][1010];
int pre[1010][1010][2];
int state[1010][1010];

void trace(int x,int y)
{
	vector<pii> vec;
	while(true)
	{
		vec.push_back(pii(x,y));
		int tx=pre[x][y][0];
		int ty=pre[x][y][1];
		x=tx,y=ty;
		if(tx==-1) break;
	}
	while(true)
	{
		int ix=vec.back().first,iy=vec.back().second;
		vec.pop_back();
		if(vec.empty()) break;
		int jx=vec.back().first,jy=vec.back().second;
		if(state[jx][jy]==1) cout<<ix<<" "<<iy;
		else if(state[jx][jy]==2) cout<<jy-2<<" "<<jy-1;
		else cout<<ix<<" "<<jy-1;
		cout<<endl;
	}
}
int main()
{
    cin>>n;
    fill(dp[0],dp[0]+1010*1010,inf);
    REP(i,n) cin>>a[i+1];
    dp[1][2]=0;
    pre[1][2][0]=-1;
    for (int i=1;i<n;i++)
    {
        for (int j=i+((i&1)?1:2);j<=n;j+=2)
        {
            //printf("dp[%d][%d] = %d\n",i,j,dp[i][j]);
            if (dp[i][j]+max(a[i],a[j])<dp[j+1][j+2])
            {
                dp[j+1][j+2]=dp[i][j]+max(a[i],a[j]);
                pre[j+1][j+2][0]=i;
                pre[j+1][j+2][1]=j;
                state[j+1][j+2]=1;
                //printf("update dp[%d][%d] = %d\n",j+1,j+2,dp[j+1][j+2]);
            }
            if (j+1<=n)
            {
                if (dp[i][j]+max(a[j],a[j+1])<dp[i][j+2])
                {
                    dp[i][j+2]=dp[i][j]+max(a[j],a[j+1]);
                    pre[i][j+2][0]=i;
                    pre[i][j+2][1]=j;
                     state[i][j+2]=2;
                    //printf("update dp[%d][%d] = %d\n",i,j+2,dp[i][j+2]);
                }
                if (dp[i][j]+max(a[i],a[j+1])<dp[j][j+2])
                {
                    dp[j][j+2]=dp[i][j]+max(a[i],a[j+1]);
                    pre[j][j+2][0]=i;
                    pre[j][j+2][1]=j;
                     state[j][j+2]=3;
                    //printf("update dp[%d][%d] = %d\n",j,j+2,dp[j][j+2]);
                }
            }
        }
    }
    if (n&1)
        REP(i,n+1) dp[i][n+1]+=a[i];
    int ans = inf;
    int x,y;
    for (int i=0;i<=n+1;i++) for (int j=n+1;j<=n+2;j++) if(dp[i][j]<ans)
	{
		ans = dp[i][j];
		x=i,y=j;
	}
    cout<<ans<<endl;
	trace(x,y);
	if(n&1) cout<<x<<endl;
    return 0;
}
